import api from "../utils/request";
import store from "../store/index";
//获取验证码
export const getCode = () => {
  return api.get("/admin/base/open/captcha");
};

//用户登录
export const getLogin = (params) => {
  return api.post("/admin/base/open/login", params);
};

//获取用户信息
export const getInfoAPI = () => {
  return api.get("/admin/base/comm/person");
};

//用户登出
export const getLoginoutAPI = () => {
  return api.post("/admin/base/comm/logout");
};

//RefreshToken的接口
//定义刷新状态
let promise = null;
export const getRefreshToken = () => {
  if (promise) {
    return promise;
  }
  promise = new Promise((resolve, reject) => {
    return api({
      url: "/admin/base/open/refreshToken",
      method: "GET",
      params: {
        refreshToken: store.state.user.refreshToken,
      },
    })
      .then((res) => {
        resolve(res);
        //将promise设置为null
        promise = null;
      })
      .catch((error) => {
        reject(error);
      });
  });
  return promise;
};
